﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using XsqTech.SmartOA.Dtos.DTO;
using XsqTech.SmartOA.IService;
using XsqTech.SmartOA.Service.DTO;

namespace XsqTech.SmartOA.Application.Controllers
{
    /// <summary>
    /// 权限控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class PermissionController : ControllerBase
    {
        IPermissionService _permissionService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public PermissionController(IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }
        /// <summary>
        /// 权限的显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public IActionResult Recursion()
        {
            return Ok(_permissionService.Recursion());
        }
        /// <summary>
        /// 权限的添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PermissionAdd(PermissionDto m)
        {
            if (!ModelState.IsValid)
            {
                return Ok(new ResponseModel() { Code = State.数据未导入, Message = "数据未导入" });
            }
            return Ok(_permissionService.PermissionAdd(m));
        }
        /// <summary>
        /// 权限的删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult PermissionDel(string id)
        {
            var data = _permissionService.PermissionDel(id);
            return Ok(data);
        }
        /// <summary>
        /// 权限的修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult PermissionUpt(PermissionDto dto)
        {
            var data = _permissionService.PermissionUpt(dto);
            return Ok(data);
        }
        /// <summary>
        /// 根据Id获取权限（返填）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("id")]
        public IActionResult PermissionGet(string id)
        {
            return Ok(_permissionService.PermissionGet(id));
        }
    }
}
